﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using D3;
using KCBF.Modules.AI.TreeSharp;
using KCBF.Modules.Config;
using NYTBD;
using NYTBD.Modules;
using Action = KCBF.Modules.AI.TreeSharp.Action;

namespace KCBF.Modules.AI.QuestSteps.Substeps
{
    class DestroyEnvironment : Decorator
    {

        private bool _isFinnished = false;
        private string _target; 

        public DestroyEnvironment(string target)
            : base(null, null)
        {
            _target = target;
            Runner = delegate(object context)
            {
                
                if (_isFinnished)
                    return false;

                Unit u = _Game.GetUnit(_target);

                if (u == null)
                    return false;

                if (Squanto.GetDistance(u.X, u.Y) > 5) return false;

                return true;
            };

            PrioritySelector seq = new PrioritySelector();

            seq.AddChild(new Action(delegate{

                Unit _u = _Game.GetUnit(_target);
                if ( _u == null) return RunStatus.Failure;
                Hero.GetSignatureSkill().use(_Game.GetUnit(_target));
                _isFinnished = true;
                return RunStatus.Failure;
                
            }));

            seq.AddChild(new WaitContinue(200, rem => false, new ActionAlwaysSucceed()));

            Children[0] = seq;
        }
    }
}
